package com.wilmar.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.wilmar.annotation.TargetDataSource;
import com.wilmar.model.UserDetail;
import com.wilmar.model.UserInfo;
import com.wilmar.service.CommonService;

@RestController
public class TestDataSourceController {

    @Autowired
    private CommonService commonService;
    
    
    @TargetDataSource(name="ds1")
    @RequestMapping(value = "/test1", method = RequestMethod.GET)
    public List<UserInfo> selectUser() {
        System.out.println("查询第一个数据源");
        return commonService.selectUserInfo();
    }

    @TargetDataSource(name="ds2")
    @RequestMapping(value = "/test2", method = RequestMethod.GET)
    public List<UserDetail> userDetail() {
        System.out.println("查询第二个数据源");
        return commonService.selectUserDetail();
    }
    
    @RequestMapping("/getAllUser")
    public List<UserInfo> getAllUser() {
    	System.out.println("使用默认数据源");
        return commonService.selectUserInfo();
    }

}